import React, { PureComponent } from 'react';
import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { Row, Col } from 'antd';
import { connect } from 'dva';
import { ModalC } from '../../../comps';
import del from '../../../assets/busi/UserManage/warning_icon.png';
@Form.create()
@connect(({ institutionConfigurationM }) => ({ institutionConfigurationM }))
export default class DeleteC extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      code: 0, //机构下是否下挂用户(0没有，1有)
    };
  }

  componentDidMount() {
    const value = {
      id: this.props.deleteId.id,
    };
    this.props.dispatch({
      type: 'institutionConfigurationM/getCheckbindById',
      payload: value,
      callback: (res) => {
        this.setState({
          code: res.code,
        });
      },
    });
  }

  // 修改visible
  changeVisible = (msg) => {
    this.props.changeVisible(msg);
  };

  // 新增/编辑 模态框内容
  addForm = () => {
    return (
      <div>
        <Form>
          <Row>
            <Col span={24}>
              <div style={{ height: '120px', textAlign: 'center', lineHeight: '120px' }}>
                <img src={del} />
              </div>
              <div style={{ color: '#FF0000', textAlign: 'center' }}>{this.state.code ? '机构下下挂了用户，是否确定删除？' : '是否确定删除？'}</div>
            </Col>
          </Row>
        </Form>
      </div>
    );
  };
  // 删除账号确认
  addanOK = () => {
    const value = {
      id: this.props.deleteId.id,
    };
    this.props.dispatch({
      type: 'institutionConfigurationM/deleteInstitutionById',
      payload: value,
      callback: (res) => {
        this.props.useGetTableData();
      },
    });
    this.changeVisible(false);
  };

  // 删除账号取消
  addanCancel = () => {
    this.changeVisible(false);
  };
  render() {
    return (
      <ModalC title={'删除'} visible={this.props.visible} maskClosable={false} onOk={this.addanOK} onCancel={this.addanCancel} width={400} height={130}>
        <div>{this.addForm()}</div>
      </ModalC>
    );
  }
}
